Sitelet https://web.archive.org/web/20210506025835/https://github.com/python/mypy/pull/10219
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

Add support for pulling configuration from pyproject.toml files #10219

Merged
merged 52 commits into from May 5, 2021

Conversation

@TheCleric
Copy link
Contributor

@TheCleric TheCleric commented Mar 17, 2021

Description

Closes #5205

This PR will add support to mypy for end users specifying configuration in a pyproject.toml file. . I also updated the documentation to indicate that this support has been added, along with some guidelines on adapting the ini configurations to the toml format.

Test Plan

I've added tests as best I could to mirror existing tests that use a mypy.ini file, but with a pyrproject.toml file, to ensure the configuration is being pulled correctly with the desired results.

@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Mar 17, 2021

Looking into the test failures. I didn't see these on my machine because I was using a venv and I think they got skipped.

@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Mar 19, 2021

Might need some help from someone with more Travis CI experience than I. It seems to be throwing strange python segmentation faults, which I am not sure where they are coming from.

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Mar 19, 2021

It looks like you may have encountered a mypyc bug (mypyc is a compiler we use to compile mypy to C extensions). I'll try to debug this, since debugging mypyc issues can be non-trivial. Sorry about that!

@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Mar 19, 2021

It looks like you may have encountered a mypyc bug (mypyc is a compiler we use to compile mypy to C extensions). I'll try to debug this, since debugging mypyc issues can be non-trivial. Sorry about that!

Thanks so much!

mypy/config_parser.py Outdated Show resolved Hide resolved
@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Mar 19, 2021

After fixing the above issue, compiled tests still fail for me. Here's what I see:

/Users/jukka/src/mypy/test-data/unit/check-custom-pyproject-plugin.test:557:
/Users/jukka/src/mypy/mypy/test/testcheck.py:138: in run_case
    self.run_case_once(testcase, ops, step)
/Users/jukka/src/mypy/mypy/test/testcheck.py:177: in run_case_once
    options = parse_options(original_program_text, testcase, incremental_step)
/Users/jukka/src/mypy/mypy/test/helpers.py:386: in parse_options
    targets, options = process_options(flag_list, require_targets=False)
mypy/main.py:855: in process_options
    ???
mypy/config_parser.py:200: in parse_config_file
    ???
mypy/config_parser.py:306: in parse_section
    ???
E   TypeError: str or None object expected; got float

This actually looks like it could be a legitimate error that mypyc was able to catch through strict runtime type checking. The type for argument section: Mapping[str, str] seems incorrect when using toml, as the value could be float, not just str.

@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Mar 19, 2021

This actually looks like it could be a legitimate error that mypyc was able to catch through strict runtime type checking. The type for argument section: Mapping[str, str] seems incorrect when using toml, as the value could be float, not just str.

Thanks, I'll fix!

TheCleric added 2 commits Mar 19, 2021
@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Mar 20, 2021

@JukkaL any clue on the strange failures on 3.5.1 with mypyc? These seem to pass everywhere else (including locally on 3.5.1), but for some reason the output prints out of order on these.

@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Apr 1, 2021

I think I'm narrowing down the issues with 3.5. TOML doesn't use an OrderedDict by default like config_parser does, so I'm working on overriding that. In Python 3.6+ dicts are ordered by default which is why this is the only version with an issue. Will have a fix soon.

@JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Apr 1, 2021

We might drop support for 3.5 soon (#9950), so maybe it's not worth worrying about? I'd also be OK with not supporting pyproject.toml on 3.5 while we wait to confirm that we can fully drop support for 3.5.

@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Apr 1, 2021

We might drop support for 3.5 soon (#9950), so maybe it's not worth worrying about? I'd also be OK with not supporting pyproject.toml on 3.5 while we wait to confirm that we can fully drop support for 3.5.

I'd be fine either way. I'll defer to those who may know more than I. 😄

@JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Apr 1, 2021

I'm fine with not supporting pyproject.toml on Python 3.5. In the next public release we can declare Python 3.5 as deprecated (even though Python 3.5 will likely still be mostly supported). Just give a clear error messages if somebody tries to use it on Python 3.5.

@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Apr 1, 2021

I'm fine with not supporting pyproject.toml on Python 3.5. In the next public release we can declare Python 3.5 as deprecated (even though Python 3.5 will likely still be mostly supported). Just give a clear error messages if somebody tries to use it on Python 3.5.

It actually works fine in Python 3.5, it's just one of the tests is failing because the order we store the data in the dict is variable since they aren't ordered. But the actual functionality is fine.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Thanks for the updates! The new config file syntax looks great to me.

Left some more minor comments.

After you've done everything else, it would be great it you can trim the test cases.

mypy/config_parser.py Outdated Show resolved Hide resolved
mypy/config_parser.py Outdated Show resolved Hide resolved
mypy/config_parser.py Outdated Show resolved Hide resolved
mypy/config_parser.py Show resolved Hide resolved
mypy/config_parser.py Outdated Show resolved Hide resolved
if not isinstance(value, str):
value = str(value)
if value.lower() not in configparser.RawConfigParser.BOOLEAN_STATES:
raise ValueError('Not a boolean: %s' % value)

This comment has been minimized.

@JukkaL

JukkaL Apr 23, 2021
Collaborator

Similar to above, raise a custom error and make sure we handle it without generating a traceback.

This comment has been minimized.

@TheCleric

TheCleric Apr 23, 2021
Author Contributor

In this case, this is the same way that the RawConfigParser does it, so I'd recommend staying consistent with how it parses booleans vs. how we do so for the TOML file.

I.e., here's what's in configparser.py:

    def _convert_to_boolean(self, value):
        """Return a boolean value translating from other types if necessary.
        """
        if value.lower() not in self.BOOLEAN_STATES:
            raise ValueError('Not a boolean: %s' % value)
        return self.BOOLEAN_STATES[value.lower()]
test-data/unit/cmdline.pyproject.test Outdated Show resolved Hide resolved
docs/source/config_file.rst Outdated Show resolved Hide resolved
mypy/config_parser.py Outdated Show resolved Hide resolved
mypy/config_parser.py Outdated Show resolved Hide resolved
@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Apr 24, 2021

@JukkaL I think other than the boolean func I left a comment on above, all the requested changes have been made.

Copy link
Collaborator

@JukkaL JukkaL left a comment

Thanks for the updates! This is almost ready to merge. It would be good to have more tests (but not as many as there were originally). Using ValueError in the boolean value parser seems okay.

-- messages and 1 if there are.

-- Directories/packages on the command line
-- ----------------------------------------

This comment has been minimized.

@JukkaL

JukkaL Apr 30, 2021
Collaborator

Could you add back some successful test cases as well that would cover all the essential features? It looks like all the test cases test failure modes.

Please add additional test cases to check-*.test files, since they are much faster than command-line tests.

This comment has been minimized.

@TheCleric

TheCleric Apr 30, 2021
Author Contributor

Sorry, got a little overzealous in the removal. Will do.

@TheCleric
Copy link
Contributor Author

@TheCleric TheCleric commented Apr 30, 2021

Thanks for the updates! This is almost ready to merge. It would be good to have more tests (but not as many as there were originally). Using ValueError in the boolean value parser seems okay.

Alright @JukkaL, I tried to find a happy medium between too few and too many tests. 😆

Let me know if I got a better balance this time.

@dciborow
Copy link

@dciborow dciborow commented Apr 30, 2021 •

as black is against supporting tox.ini, this is extra important to me to eventually have all of our configurations in a single spot...

psf/black#2172

Right now we can not configure both black and mypy into the same file as black lacks support for tox.ini

@JelleZijlstra , watching is closely.

(But am going to stand by the fact I think black should make the reverse effort here to support ini files as well, particularly if this does not gain traction again)

@JukkaL
JukkaL approved these changes May 5, 2021
Copy link
Collaborator

@JukkaL JukkaL left a comment

Thanks for the final batch of updates! Looks good now.

@JukkaL JukkaL merged commit fdeedd6 into python:master May 5, 2021
7 checks passed
7 checks passed
@github-actions
Comment
Details
@github-actions
Run (0)
Details
@github-actions
build (windows-py37-32)
Details
@github-actions
Run (1)
Details
@github-actions
build (windows-py37-64)
Details
@github-actions
Run (2)
Details
@travis-ci
Travis CI - Pull Request Build Passed
Details
Gobot1234 added a commit to Gobot1234/steam.py that referenced this pull request May 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

6 participants