Skip to content

Commit

Permalink
resolved conflict with python 3.9 dataclasses.Field signature
Browse files Browse the repository at this point in the history
  • Loading branch information
o-murphy committed Apr 4, 2024
1 parent 89b9080 commit 03204df
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions py_ballisticcalc/unit.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
"""
Useful types for prefer_units of measurement conversion for ballistics calculations
"""

import sys
from abc import ABC
from dataclasses import dataclass, MISSING, Field, fields
from enum import IntEnum
from math import pi, atan, tan
from typing import NamedTuple
from typing import NamedTuple, Union

__all__ = ('Unit', 'AbstractUnit', 'UnitProps', 'UnitPropsDict', 'Distance',
'Velocity', 'Angular', 'Temperature', 'Pressure',
Expand Down Expand Up @@ -662,15 +662,43 @@ def __setattr__(self, key, value):


# pylint: disable=redefined-builtin,too-few-public-methods,too-many-arguments
# class Dimension(Field):
# """
# Definition of measure units specified field for
# PreferredUnits.Mixine based dataclasses
# """
#
# def __init__(self, prefer_units: [str, Unit], init=True, repr=True,
# hash=None, compare=True, metadata=None, kw_only=MISSING):
# if metadata is None:
# metadata = {}
# metadata['prefer_units'] = prefer_units
# super().__init__(None, MISSING, init, repr, hash, compare, metadata, kw_only)


class Dimension(Field):
"""
Definition of measure units specified field for
PreferredUnits.Mixine based dataclasses
"""

def __init__(self, prefer_units: [str, Unit], init=True, repr=True,
hash=None, compare=True, metadata=None, kw_only=MISSING):
def __init__(self, prefer_units: Union[str, Unit], init=True, repr=True,
hash=None, compare=True, metadata=None):
if metadata is None:
metadata = {}
metadata['prefer_units'] = prefer_units
super().__init__(None, MISSING, init, repr, hash, compare, metadata, kw_only)


major, minor = sys.version_info.major, sys.version_info.minor

if major >= 3 and minor > 9:
extra = {'kw_only': MISSING}
elif major >= 3 and minor == 9:
extra = {}
else:
raise RuntimeError("Unsupported python version")

super().__init__(default=None, default_factory=MISSING,
init=init, repr=repr,
hash=hash, compare=compare,
metadata=metadata, **extra)

0 comments on commit 03204df

Please sign in to comment.