Skip to content
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

Enable the use of mypy --no-explicit-reexport on downstream projects #338

Merged
merged 1 commit into from
Jan 29, 2024

Conversation

dkg
Copy link
Contributor

@dkg dkg commented Jan 28, 2024

When testing simple python code like this with mypy for type-safety:

import gssapi
gsc:gssapi.SecurityContext
gsc = gssapi.SecurityContext(
       usage='initiate',
       name=gssapi.Name('imap@localhost',
                        gssapi.NameType.hostbased_service))

I see these errors:

0 $ mypy --no-implicit-reexport ./test.py
test.py:3: error: Name "gssapi.SecurityContext" is not defined  [name-defined]
test.py:4: error: Module "gssapi" does not explicitly export attribute "SecurityContext"  [attr-defined]
test.py:4: error: Module "gssapi" does not explicitly export attribute "Name"  [attr-defined]
test.py:4: error: Module "gssapi" does not explicitly export attribute "NameType"  [attr-defined]
Found 4 errors in 1 file (checked 1 source file)
1 $

The same thing happens when using mypy --strict.

a blogpost suggested that the __all__ variable in gssapi/__init__.py might be the way to fix this.

I can confirm that it does clear the error, but I'm not enough of a python module expert to know whether there might be some undesirable side effects as well to making this change. Please review!

Tested on debian testing/unstable, with:

  • python3 3.11.6-1
  • python3-gssapi 1.8.2-1+b2
  • mypy 1.8.0-1

jborean93

This comment was marked as outdated.

Copy link
Contributor

@jborean93 jborean93 left a comment

Choose a reason for hiding this comment

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

Thanks for the fix, looks like the line length is too long and has hit the flake sanity test. You can do something like

__all__ = [
    "SecurityContext",
    "Name",
    ...
    "set_encoding",
]

When testing simple python code like this with mypy for type-safety:

```
import gssapi
gsc:gssapi.SecurityContext
gsc = gssapi.SecurityContext(
       usage='initiate',
       name=gssapi.Name('imap@localhost',
                        gssapi.NameType.hostbased_service))
```

I see these errors:

```
0 $ mypy --no-implicit-reexport ./test.py
test.py:3: error: Name "gssapi.SecurityContext" is not defined  [name-defined]
test.py:4: error: Module "gssapi" does not explicitly export attribute "SecurityContext"  [attr-defined]
test.py:4: error: Module "gssapi" does not explicitly export attribute "Name"  [attr-defined]
test.py:4: error: Module "gssapi" does not explicitly export attribute "NameType"  [attr-defined]
Found 4 errors in 1 file (checked 1 source file)
1 $
```

The same thing happens when using `mypy --strict`.

[a
blogpost](https://til.codeinthehole.com/posts/how-to-handle-convenience-imports-with-mypy/)
suggested that the `__all__` variable in `gssapi/__init__.py` might be
the way to fix this.

I can confirm that it does clear the error, but I'm not enough of a
python module expert to know whether there might be some undesirable
side effects as well to making this change.  Please review!

Tested on debian testing/unstable, with:

- python3  3.11.6-1
- python3-gssapi 1.8.2-1+b2
- mypy 1.8.0-1

Signed-off-by: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
@jborean93
Copy link
Contributor

I'll have to look into why the build is failing, maybe cibuildwheel pushed an update which broke something.

@dkg
Copy link
Contributor Author

dkg commented Jan 29, 2024

thanks for the prompt review, @jborean93 ! let me know if you need anything else.

@jborean93
Copy link
Contributor

Looks like a temporary problem, rerunning a few hours later and it now works.

@jborean93 jborean93 merged commit b72364d into pythongssapi:main Jan 29, 2024
46 checks passed
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.

None yet

2 participants