Isort: Incorrect third vs first party categorization - namespace packages

Created on 1 Sep 2020  ยท  9Comments  ยท  Source: PyCQA/isort

https://github.com/PyCQA/isort/blob/develop/isort/place.py#L65-L71 only considers the root module name when trying to categorize a package as first party. This causes issues when your project only contains a part of that module (e.g. in case of namespace packages). Setting known_first_party to root.a will mean that root.b will also be categorized as first party even though it's third party:

root
โ”œโ”€โ”€ __init__.py
โ”œโ”€โ”€ a
โ”‚   โ””โ”€โ”€ __init__.py
โ””โ”€โ”€ b
    โ””โ”€โ”€ __init__.py
bug

Most helpful comment

Thanks for reporting this issue! This is an embarrassing omission on my part. I had hoped to get a fix for this out in for 5.5.0, but I don't want to rush the change while pushing out some changes needed for improved VSCode integration. Expect to see this fixed in the next minor release (5.6.0)

Thanks!

~Timothy

All 9 comments

Thanks for reporting this issue! This is an embarrassing omission on my part. I had hoped to get a fix for this out in for 5.5.0, but I don't want to rush the change while pushing out some changes needed for improved VSCode integration. Expect to see this fixed in the next minor release (5.6.0)

Thanks!

~Timothy

I think this is happening to us too https://github.com/PyCQA/isort/issues/1467

@timothycrosley any ETA on this?

@gaborbernat the next minor release is scheduled for October 1st, I'll try to make sure the change is in develop soon so that you and others can test the new functionality before it's released to PyPI

This is fixed in develop and, void of issues being discovered before then, will be deployed with the 5.6.0 release of isort tonight.

The solution as coded exposes two new configuration options to tweak the behaviour if needed:

  • auto_identify_namespace_packages (defaults to True): enables toggling the new automatic namespace package identification.
  • namespace_packages: Enables manually specifying a list of namespace packages.

Thanks!

~Timothy

Was this released part of 5.5.5 and just msised from the changelog? ๐Ÿค”

@gaborbernat nope! There will be another release tonight, but since it is rather large for a minor release I wanted to make sure that the one major issue in the 5.5.x series was released separately in case any of the changes in 5.6.0 are harder to accommodate by any individual projects

This is now live with release 5.6.0 of isort https://pycqa.github.io/isort/CHANGELOG/#560-october-7-2020.

I apologize for the extended timeline for the release, but hope there are enough good things in it to make up for it!

No worries, much appreciated now it's released

clap

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jedie picture jedie  ยท  3Comments

ionelmc picture ionelmc  ยท  3Comments

donjar picture donjar  ยท  3Comments

cjerdonek picture cjerdonek  ยท  3Comments

lee-kagiso picture lee-kagiso  ยท  4Comments