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

fix ignoring pyproject.toml config #25

Merged
merged 1 commit into from
Oct 17, 2024

Conversation

deliro
Copy link

@deliro deliro commented Oct 17, 2024

Hi! We faced the problem that mypy-baseline's config in pyproject.toml is completely ignored for boolean flags.
I did some investigations and here's what I found:

Config is read:

@classmethod
def from_args(cls, args: dict[str, Any]) -> Config:
    config = cls()
    config = config.read_file(args['config'])
    config = config.read_args(args)  # <-- args overwrite config (which is the right thing)
    if isinstance(config.baseline_path, str):
        config.baseline_path = Path(config.baseline_path)
    return config

Args are read:

def read_args(self, args: dict[str, Any]) -> Config:
    config = dataclasses.replace(self)
    for field in dataclasses.fields(self):
        value = args[field.name]
        if value is not None:  # <-- set only if arg is not None
            setattr(config, field.name, value)
    return config

But parser args are defined this way:

add(
    '--allow-unsynced', action='store_true',
    help='do not fail for resolved violations.'
)
add(
    '--preserve-position', action='store_true',
    help='do not remove line number from the baseline.',
)

In this case, store_true acts like an on/off switch. If an argument is not set, it defaults to False (what is not None)

Thus, all the unspecified flags in the CLI overwrite any flags from the config

Copy link

netlify bot commented Oct 17, 2024

Deploy Preview for mypy-baseline failed.

Name Link
🔨 Latest commit e241459
🔍 Latest deploy log https://app.netlify.com/sites/mypy-baseline/deploys/6710c28af066670008908184

@orsinium
Copy link
Member

Thank you!

@orsinium orsinium merged commit 16cc030 into orsinium-labs:master Oct 17, 2024
2 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants