Python 3.6: A quick look

The new version of Python, version 3.6, is planned to be released on Friday December 16th. Let’s take a quick look at the new features that are included in this release, and play around with it a little.

Python 3.6 has many new cool features, like format strings, a secrets module, file system protocol, and more. If you want to read more about all features, check out python.org.

To show some of what can be done in the new language, let’s create a simple application in modern Python, and then see how we can upgrade it with Python 3.6 features.

Quick disclaimer: this post is not a full list of Python 3.6 features, if you’re interested in that, check out python.org, they have a great summary. This post shows how to actually use some of the new features to improve your programming. And we’ll show you how to use PyCharm with the new Python features.

Now that that’s out of the way, let’s have a look at the application we’ll be upgrading.

The Application

We will make a very simple single-file application, that will take a URL to a file, and download the file while simultaneously calculating the file’s sha256 checksum. If you would like to follow along, check out the GitHub repo. The master branch contains the Python 3.6 code, and the ‘python-3.5’ branch contains the Python 3.5 code.

Now let’s have a look how we can do this in Python 3.5:

The main parses the argument (the URL) and then starts the asyncio event loop. If you’ve never worked with asyncio before, check out Nick Coghlan’s introduction.

The core of the code is in the download_url function, aiohttp is used to asynchronously download the file in byte-sized chunks (set using the ‘chunk_size’ constant at the top of the file).

As every chunk is received, the sha256sum calculation is updated with the newly received chunk, and that chunk is saved to the disk.

To run the code, first install the dependencies using pip install -r requirements.txt, and then run download.py <URL>. This should result in the following output:

sha256downloader in action

So now let’s see how we can make our application better with Python 3.6 features!

Python 3.6

The first thing we can do is use those fancy new f-strings. Most Python programmers are probably aware that there are several methods in Python to insert data into a string. The classic way would be using the ‘%’ operator, which has been deprecated due to several issues (see PEP 3101). A newer method would be using either string.format class method, or the str.format instance method on a specific string.

In Python 3.6 a new notation is introduced, which combines the variables with the format string, in a way which looks similar to a templating language:

If you’re using PyCharm, it can help you convert these statements: just put your caret in the formatted string, and use Alt+Enter to select the “convert to f-string literal’ intention.

F-string conversion intention

Afterwards these statements will look like this:

Another new feature in Python 3.6 are underscores in numbers, which allows us to add an underscore to the chunk_size constant. This makes it slightly easier to read:

Currently, the download_url function isn’t looking very pretty, a fair amount of boilerplate is mixed in with the business logic. We can’t make it all go away without some serious development, but we can separate some of the flow control away from the business logic using Python 3.6 features. In Python 3.5 and earlier, using a yield statement in an async function was a SyntaxError. In the new Python version asynchronous generators are supported, so we can restructure the while True into a closure which exposes a generator.

There’s one more change that we can make to make our lives easier: we can add an annotation to the file_hash variable. If you were to type file_hash. you currently wouldn’t see any code completion due to the way that hashlib instances the object. We can help PyCharm (and any other static code analysis tool) out by adding a type annotation:

After adding the annotation (and the _sha256 import statement at the top of the document), PyCharm’s code completion works as intended:

Code completion working after adding type annotation

In this specific case it isn’t recommended to add this annotation, as the _sha256 module is annotated as a private. However, the way to add annotations is the same for all classes.

A quick note about type annotations: they don’t change anything about how the program works. If you store a number in a variable you annotate as a string, the python interpreter will just ignore your annotation. The annotations are purely for external tools that can analyze your code.

There are more features in Python 3.6, if you’d like to learn about them go to python.org.

PyCharm 2016.3 fully supports Python 3.6, so get the repo and play around. If you don’t have PyCharm 2016.3 yet, have a look and see what’s new.

-PyCharm Team
The Drive to Develop

Posted in Uncategorized | 9 Comments

PyCharm 2016.3.1 RC Available

We’re happy to announce the availability of PyCharm 2016.3.1 RC. We’ve worked hard to fix some issues some of you are facing:

  • If you would like to disable the automatic activation of the project’s virtualenv, you can now disable this setting in Settings | Tools | Terminal | Activate virtualenv
  • Terminal path can be configured globally
  • The terminal on macOS will source your bash_profile upon activation
  • HTML tags automatically close in Django templates
  • Python Console: Execute code in console (Shift+Alt+E) indentation fixed, tab completion
  • And various other bugs, see the release notes for details

Get it now from the EAP page!

Although we pay careful attention to make sure our software works well, if you experience any issues please report them on our issue tracker. If you have any ideas about how we can make PyCharm better, please let us know on our issue tracker as well!

The Drive to Develop

-PyCharm Team

Posted in Early Access Preview | 8 Comments

“What’s New in PyCharm 2016.3” Webinar Recording Available Now!

Our webinar “What’s New in PyCharm 2016.3” that we organized on Wednesday November 30th is now available on YouTube:

In this webinar Paul Everitt, PyCharm Developer Advocate, shows you around the new features in PyCharm 2016.3 (and shows some other great features that were introduced in 2016).

He discusses improvements to Django (at 1:33), web development support (at 6:07), database support (at 14:45), and more. PyCharm Professional bundles all the new functionality of the latest versions of WebStorm and DataGrip.

After introducing some of these features, he shows how to create a 2D game in Python using the Python Arcade library (from 17:26 onwards). In the process he shows how to unit test the game, profile the game, and how to debug the game faster.

If you’d like to follow along and play with the code, you can get it from Paul’s GitHub repository.

Keep up with the latest PyCharm news on this blog, and follow us on Twitter (@PyCharm)

The Drive to Develop

-PyCharm Team

Posted in Webinar | Leave a comment

PyCharm 2016.3 Released

We are happy to announce the availability of PyCharm 2016.3. Get it now from our website.

We have worked hard on bringing you a better IDE, PyCharm 2016.3 comes with these features:

  • Better Django support
  • Improved Python console
  • Full support for Python 3.6
  • Enhanced version control integration
  • A better variable explorer
  • Upgrades to coverage and profiling tools
  • And much more, see the what’s new page

Next Wednesday (November 30th) at 3pm GMT (4pm European, 10am Eastern) we’re organizing a webinar where Paul Everitt, our developer advocate, introduces PyCharm’s new features, sign up here!

If you got your PyCharm license before November 2015, we have a special offer for you! Don’t miss out on these new features: switch to a subscription and get 40% off your monthly payments until your subscription expires. This offer is valid until the end of the year. Switch now in the JetBrains store.

We want to make sure that PyCharm will remain the best Python IDE, if you know a feature we could add to make it better for you, please let us know on our issue tracker!

-PyCharm Team

Posted in Release Announcements | 17 Comments

PyCharm 2016.3 Release Candidate 2

We are happy to announce the availability of PyCharm 2016.3 RC 2. We are approaching the release of 2016’s third major PyCharm update, and it’s available for preview now. Download it now from the preview page.

Since the previous public preview we’ve fixed several bugs: details in the release notes.

If you haven’t seen our public preview yet, check out the preview page to learn about the features included in the new version. Some highlights:

  • Better Django support
  • Improved Python console
  • Enhanced version control integration
  • And much more

If you still have a perpetual license for an earlier version of PyCharm, we have a special offer for you! Don’t miss out on these new features: switch to a subscription and get 40% off forever. This offer is valid until the end of the year. Switch now in the JetBrains store.

Although we do our best to make sure that release candidates work well, if you experience any issues please report them on our issue tracker. Of course new feature requests are welcome there as well!

-PyCharm Team

Posted in Uncategorized | Leave a comment

PyCharm 5 and 2016.1: PyPI Compatibility Hotfix

The Python Package Index (PyPI) has recently upgraded its caching infrastructure, which broke our integration with their service. We contacted them to restore this functionality temporarily, and now we’ve prepared a hotfix to make sure earlier PyCharm versions will continue to work into the future.

If you are using PyCharm 5 or PyCharm 2016.1 please update today (Help | Check for Updates) to make sure you won’t be affected when PyPI deactivates their now deprecated API.

Full installers for previous versions of PyCharm can be downloaded from the previous versions confluence page.

-PyCharm Team

Posted in Release Announcements | 2 Comments

PyCharm 2016.3 Release Candidate

We are happy to announce the availability of PyCharm 2016.3 Release Candidate. We are approaching the release of 2016’s third major PyCharm update, and it’s available for preview now. Download it now from the preview page.

Since the previous public preview we’ve fixed several bugs: details in the release notes.

If you haven’t seen our public preview yet, check out the preview page to learn about the features included in the new version. Some highlights:

  • Better Django support
  • Improved Python console
  • Enhanced version control integration
  • And much more

If you still have a perpetual license for an earlier version of PyCharm, we have a special offer for you! Don’t miss out on these new features: switch to a subscription and get 40% off forever. This offer is valid until the end of the year. Switch now in the JetBrains store.

Although we do our best to make sure that release candidates work well, if you experience any issues please report them on our issue tracker. Of course new feature requests are welcome there as well!

-PyCharm Team

Posted in Early Access Preview | 2 Comments

Webinar: What’s New in PyCharm 2016.3, November 30th

Join us Wednesday, November 30, 2016, at 16:00 – 17:00 CET (check other time zones) for the free webinar What’s New in PyCharm 2016.3 with Paul Everitt.

pycharm_webinar_what_s_new_in_pycharm_2016_3

PyCharm 2016.3 is the third update in the 2016 series of releases. During this webinar, Paul Everitt gives a quick overview of the new features and improvements, including:

  • Django: Create Django projects with remote interpreters, Django forms in class-based views
  • Python: Full 3.6 support, improved variable explorer, Python console copy-paste made easier, numpy array and pandas dataframe viewer straight from the debugger, terminal with virtualenv pre-activated, Per-line vmprof profiling
  • Web: ES6 Refactorings
  • VCS: Undo commit
  • Database: Edit many database cells at once
  • Platform: Fira font ligatures

Register for the webinar and then join us as we demonstrate many of the new features and take questions live.

To follow updates on this release, please visit the 2016.3 landing page.

About Paul Everitt

Paul Everitt is the PyCharm Developer Advocate at JetBrains. Before that, Paul was a co-founder of Agendaless Consulting and a co-founder of Zope Corporation, taking the first open source application server through $14M of funding. Paul has bootstrapped both the PSF and the Python Software Foundation. Prior to that, Paul was an officer in the US Navy, starting in Python and launching www.navy.mil in 1993.

Posted in Webinar | 9 Comments

Help us make a great PyCon US tutorial proposal

tl;dr Fresh new tutorial techniques and testimonials solicited

PyCon US 2017 is around the corner if you stretch your neck and have good eyesight. More specifically, the deadline for tutorial proposals is right on our doorstep. We’ve been hatching a good idea for a tutorial, putting a lot of work into finding some clever new approaches and would like some ideas from our PyCharmers.

And selfishly, we’d like some testimonials we can submit if you attended our EuroPython or PyCon India tutorials.

Our tutorial idea is “Debugging for the Masses…Visually”. Our thesis: lots of people aren’t using the debugger, or aren’t using it fully. We’d like to help them get over the hump with some new twists, starting with a visual approach to debugging, using the free and open source PyCharm Community Edition.

We have some unique ideas planned:

  • The tutorial builds a 2d game in Python, introducing debugging concepts along the way
  • A twist on the presentation style
  • Animated visuals to explain hard-to-grasp concepts
  • And more…

Here’s an open call to PyCharmers…step back from the normal tutorial and think big. What are some fresh new ideas for a tutorial on making people productive with debugging?

And if you’ve gone to one of my tutorials (PyCharm, Pyramid, Plone, Python) over the years, please drop a note in the comments if you liked it. It’s a helpful part of a strong proposal submission, and we’re really working hard to deliver something special.

Posted in Uncategorized | 2 Comments

PyCharm 2016.3 Public Preview 3

This week’s public preview version is out now! If you want to try out the 2016.3 features now, get it from the preview page. As a preview version, it comes with a free 30-day preview license.

Since last week, we’ve:

  • Improved Jupyter Notebook (previously known as IPython Notebooks) support: split and merge cells, customized command line arguments, and support for IPython profiles. We’ve also fixed a lot of bugs.
  • Added support for node.js Yarn tasks.
  • And fixed a lot of bugs

You can see all the new features since 2016.2 and try out the new version on the preview page. For more details on what’s new, check out the release notes.

If you want to receive the new preview version every week, set your update channel (Help > Check for Updates, and then click the ‘updates’ link) to “Early Access Program” or “Beta Releases or Public Preview”.

If you find any bugs in PyCharm, or would like to request a feature, please let us know on the issue tracker!

-PyCharm Team

Posted in Early Access Preview | 12 Comments