Skip to content

Add imports of int values to .pyi files #225

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 27, 2021
Merged

Add imports of int values to .pyi files #225

merged 1 commit into from
Dec 27, 2021

Conversation

daviddrysdale
Copy link
Owner

A statement like from .local import THING in current.py makes
THING available in the current module, but this also acts as ani
export (i.e. current.THING is defined).

As of version 0.930 of mypy, the stubtest checker wants to see a
type definition for such things, when they are ints or strings.

Add the equivalent from .local import THING statements into the
.pyi stub files, so stubtest can see the associated type definition.

For autogenerated *data/__init__.pyi files, this involves a change to
the metadata generation tool.

Also:

  • Fix asyoutypeformatter.py to import REGION_CODE_FOR_NON_GEO_ENTITY
    from phonemetadata (the definition) rather than phonenumberutil
    (a re-export).
  • Rename local loop variables to start with an underscore in
    (autogenerator for) *data/__init__.py so they don't look like
    things that should be exported.
  • Drop version pin (==0.921) for mypy. Fixes Remove mypy version pin #224.

A statement like `from .local import THING` in `current.py` makes
`THING` available in the current module, but this also acts as ani
export (i.e. `current.THING` is defined).

As of version 0.930 of mypy, the `stubtest` checker wants to see a
type definition for such things, when they are ints or strings.

Add the equivalent `from .local import THING` statements into the
.pyi stub files, so `stubtest` can see the associated type definition.

For autogenerated `*data/__init__.pyi` files, this involves a change to
the metadata generation tool.

Also:
 - Fix asyoutypeformatter.py to import `REGION_CODE_FOR_NON_GEO_ENTITY`
   from `phonemetadata` (the definition) rather than `phonenumberutil`
   (a re-export).
 - Rename local loop variables to start with an underscore in
   (autogenerator for) `*data/__init__.py` so they don't look like
   things that should be exported.
 - Drop version pin (==0.921) for mypy.  Fixes #224.
Comment on lines +3 to +48
from .alt_format_255 import PHONE_ALT_FORMAT_255
from .alt_format_27 import PHONE_ALT_FORMAT_27
from .alt_format_30 import PHONE_ALT_FORMAT_30
from .alt_format_31 import PHONE_ALT_FORMAT_31
from .alt_format_34 import PHONE_ALT_FORMAT_34
from .alt_format_350 import PHONE_ALT_FORMAT_350
from .alt_format_351 import PHONE_ALT_FORMAT_351
from .alt_format_352 import PHONE_ALT_FORMAT_352
from .alt_format_358 import PHONE_ALT_FORMAT_358
from .alt_format_359 import PHONE_ALT_FORMAT_359
from .alt_format_36 import PHONE_ALT_FORMAT_36
from .alt_format_372 import PHONE_ALT_FORMAT_372
from .alt_format_373 import PHONE_ALT_FORMAT_373
from .alt_format_380 import PHONE_ALT_FORMAT_380
from .alt_format_381 import PHONE_ALT_FORMAT_381
from .alt_format_385 import PHONE_ALT_FORMAT_385
from .alt_format_39 import PHONE_ALT_FORMAT_39
from .alt_format_43 import PHONE_ALT_FORMAT_43
from .alt_format_44 import PHONE_ALT_FORMAT_44
from .alt_format_49 import PHONE_ALT_FORMAT_49
from .alt_format_505 import PHONE_ALT_FORMAT_505
from .alt_format_506 import PHONE_ALT_FORMAT_506
from .alt_format_52 import PHONE_ALT_FORMAT_52
from .alt_format_54 import PHONE_ALT_FORMAT_54
from .alt_format_55 import PHONE_ALT_FORMAT_55
from .alt_format_58 import PHONE_ALT_FORMAT_58
from .alt_format_595 import PHONE_ALT_FORMAT_595
from .alt_format_61 import PHONE_ALT_FORMAT_61
from .alt_format_62 import PHONE_ALT_FORMAT_62
from .alt_format_64 import PHONE_ALT_FORMAT_64
from .alt_format_66 import PHONE_ALT_FORMAT_66
from .alt_format_675 import PHONE_ALT_FORMAT_675
from .alt_format_676 import PHONE_ALT_FORMAT_676
from .alt_format_679 import PHONE_ALT_FORMAT_679
from .alt_format_7 import PHONE_ALT_FORMAT_7
from .alt_format_81 import PHONE_ALT_FORMAT_81
from .alt_format_84 import PHONE_ALT_FORMAT_84
from .alt_format_855 import PHONE_ALT_FORMAT_855
from .alt_format_856 import PHONE_ALT_FORMAT_856
from .alt_format_90 import PHONE_ALT_FORMAT_90
from .alt_format_91 import PHONE_ALT_FORMAT_91
from .alt_format_94 import PHONE_ALT_FORMAT_94
from .alt_format_95 import PHONE_ALT_FORMAT_95
from .alt_format_971 import PHONE_ALT_FORMAT_971
from .alt_format_972 import PHONE_ALT_FORMAT_972
from .alt_format_995 import PHONE_ALT_FORMAT_995
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't include these on the original types PR as I thought it'd mean you need to go all the way and add per-file typing -- brilliant that it seems to work!

(Sorry also for causing the extra work here, perhaps I cut some corners in the original work!)
A

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, I don't think any corners were cut – it's just that the latest mypy behaves differently from previous versions when checking relative imports of ints/strings from submodules: python/mypy#11843.

Copying across the relevant imports from .py to .pyi files seems to make things work again…

@daviddrysdale daviddrysdale merged commit 038a589 into dev Dec 27, 2021
@daviddrysdale daviddrysdale deleted the pyi-imports branch December 27, 2021 17:33
daviddrysdale added a commit that referenced this pull request Jan 11, 2022
Commit 038a589 ("Add imports of int values to .pyi files (#225)")
removed the need for a mypy version pin, but missed one of the places
where it was pinned.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Remove mypy version pin
2 participants