Skip to content

Integrate mypy #26

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

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# This workflow will install Python dependencies, run tests and lint with a variety of Python versions
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-python

name: Python package

on:
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

jobs:
test:

runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest]
python-version:
- "3.7"
- "3.8"
- "3.9"
- "3.10"
- "3.11"
- "3.12"
- "pypy3.6"
- "pypy3.7"
- "pypy3.8"
- "pypy3.9"
- "pypy3.10"
include:
# Python 3.6 is not available on ubuntu-latest,
# so use ubuntu-20.04 for it:
- python-version: "3.6"
os: ubuntu-20.04

steps:
- uses: actions/checkout@v4
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v5
with:
python-version: ${{ matrix.python-version }}
allow-prereleases: true
- name: Install dependencies
run: |
python -m pip install -U pip
pip install .
pip install -r requirements-test.txt
- name: Test with pytest
run: |
pytest

lint:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- uses: pre-commit/[email protected]

type:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: "3.12"
- run: |
python -m pip install -U pip
pip install .
pip install -r requirements-type.txt
- run: |
mypy src/
99 changes: 0 additions & 99 deletions .github/workflows/pythonpackage.yml

This file was deleted.

29 changes: 9 additions & 20 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,47 +1,36 @@
default_language_version:
python: python3.12
repos:
- repo: 'https://github.com/pre-commit/pre-commit-hooks'
rev: v3.2.0
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer
- repo: 'https://github.com/PyCQA/flake8'
rev: 4.0.1
rev: 7.0.0
hooks:
- id: flake8
- repo: 'https://github.com/pre-commit/mirrors-isort'
rev: v5.10.1
hooks:
- id: isort
- repo: 'https://github.com/mgedmin/check-manifest'
rev: '0.46'
rev: '0.49'
hooks:
- id: check-manifest
- repo: 'https://github.com/myint/autoflake'
rev: v1.4
rev: v2.3.0
hooks:
- id: autoflake
args:
- '--remove-all-unused-imports'
- '-i'
language_version: python3.9
- repo: 'https://github.com/pre-commit/mirrors-autopep8'
rev: v1.5.7
hooks:
- id: autopep8
language_version: python3.9
- repo: https://github.com/psf/black
rev: 22.3.0
- repo: https://github.com/psf/black-pre-commit-mirror
rev: 24.2.0
hooks:
- id: black
language_version: python3.9
- repo: https://github.com/ikamensh/flynt/
rev: '0.76'
hooks:
- id: flynt
language_version: python3.9
- repo: https://github.com/asottile/pyupgrade
rev: v2.31.1
rev: v3.15.1
hooks:
- id: pyupgrade
entry: pyupgrade --py3-plus --py36-plus --keep-runtime-typing
language_version: python3.9
3 changes: 1 addition & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
[tool.black]
line-length = 120
# required-version = '22.3.0' # see https://github.com/psf/black/issues/2493
target-version = ['py39']
target-version = ["py36", "py37", "py38", "py39", "py310", "py311", "py312"]

[tool.isort]
profile = "black"
Expand Down
3 changes: 0 additions & 3 deletions requirements-linters.txt

This file was deleted.

2 changes: 2 additions & 0 deletions requirements-type.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mypy>=1.8.0
types-pytz
4 changes: 0 additions & 4 deletions requirements.txt

This file was deleted.

1 change: 1 addition & 0 deletions src/fluent_compiler/ast_compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def NewAst(...):
NewAst = ast.NewAst

"""

import ast
import sys

Expand Down
2 changes: 1 addition & 1 deletion src/fluent_compiler/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ def as_ast(self):
return ast.Name(id=self.name, ctx=ast.Load(), **DEFAULT_AST_ARGS)

def __eq__(self, other):
return type(other) == type(self) and other.name == self.name
return isinstance(other, type(self)) and other.name == self.name

def __repr__(self):
return f"VariableReference({repr(self.name)})"
Expand Down
1 change: 0 additions & 1 deletion src/fluent_compiler/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ class NumberFormatOptions:


class FluentNumber(FluentType):

default_number_format_options = NumberFormatOptions()

def __new__(cls, value, **kwargs):
Expand Down
1 change: 0 additions & 1 deletion src/fluent_compiler/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ def attribute_ast_to_id(attribute, parent_ast):


def allowable_name(ident, for_method=False, allow_builtin=False):

if keyword.iskeyword(ident):
return False

Expand Down
1 change: 1 addition & 0 deletions tests/format/test_escapers.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def join(self, parts):
# that, unlike HtmlEscaper above, the output type is not a subclass of
# str, in order to test the implementation handles this properly.


# We also test whether the implementation can handle subclasses
class Markdown:
def __init__(self, text):
Expand Down
2 changes: 0 additions & 2 deletions tests/test_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ def currency(amount, *args, **kwargs):


class TestFluentNumber(unittest.TestCase):

locale = Locale.parse("en_US")

def setUp(self):
Expand Down Expand Up @@ -189,7 +188,6 @@ def test_copy_attributes(self):


class TestFluentDate(unittest.TestCase):

locale = Locale.parse("en_US")

def setUp(self):
Expand Down
35 changes: 14 additions & 21 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
# This config is for local testing. Where needed changes should be duplicated into
# .github/workflows/pythonpackage.yml
[tox]
envlist = py36,py37,py38,py39,py310,py311,py312,pypy3.6,flake8,isort
envlist =
py{36,37,38,39,310,311,312},
pypy{3.6,3.7,3.8,3.9,3.10},
lint,
type,
# For Python 3.6 support:
requires = virtualenv<20.22.0

[testenv]
deps =
# Just '.[develop]' would be nice here.
# Unfortunately it is super slow: https://github.com/pypa/pip/issues/2195
# So we duplicate deps from setup.py for now.
-r{toxinidir}/requirements.txt
-r{toxinidir}/requirements-test.txt
-r{toxinidir}/requirements-linters.txt
deps = -r{toxinidir}/requirements-test.txt
commands = pytest

[testenv:lint]
base_python = py312
deps = pre-commit
commands = pre-commit run --all-files --show-diff-on-failure

[testenv:flake8]
basepython = python3.9
commands = flake8 src tests


[testenv:isort]
basepython = python3.9
commands = isort -c src tests

[testenv:check-manifest]
basepython = python3.9
deps = check-manifest
commands = check-manifest
[testenv:type]
base_python = py312
deps = -r{toxinidir}/requirements-type.txt
commands = mypy src/