Skip to content

Commit

Permalink
remove __name__ attribute shadowing class name
Browse files Browse the repository at this point in the history
  • Loading branch information
cleder committed Dec 11, 2023
1 parent 6900b91 commit 7af7903
Show file tree
Hide file tree
Showing 16 changed files with 36 additions and 117 deletions.
30 changes: 19 additions & 11 deletions fastkml/atom.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,24 @@ def check_email(email: str) -> bool:
return bool(email_match(email))


class Link(_XMLObject):
class _AtomObject(_XMLObject):
"""
Baseclass for Atom Objects.
Atom objects are used in KML to provide information about the author and
related website in your KML file. This information is displayed in geo
search results, both in Earth browsers such as Google Earth, and in other
applications such as Google Maps.
The atom tag name is the class name in lower case.
"""

@classmethod
def get_tag_name(cls) -> str:
"""Return the tag name."""
return cls.__name__.lower()


class Link(_AtomObject):
"""
Identifies a related Web page. The rel attribute defines the type of relation.
A feed is limited to one alternate per type and hreflang.
Expand All @@ -62,8 +79,6 @@ class Link(_XMLObject):
title, and length.
"""

__name__ = "link"

href: Optional[str]
# href is the URI of the referenced resource

Expand Down Expand Up @@ -170,15 +185,13 @@ def _get_kwargs(
return kwargs


class _Person(_XMLObject):
class _Person(_AtomObject):
"""
<author> and <contributor> describe a person, corporation, or similar
entity. It has one required element, name, and two optional elements:
uri, email.
"""

__name__ = ""

name: Optional[str]
# conveys a human-readable name for the person.

Expand Down Expand Up @@ -216,7 +229,6 @@ def etree_element(
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> Element:
self.__name__ = self.__class__.__name__.lower()
element = super().etree_element(precision=precision, verbosity=verbosity)
if self.name:
name = config.etree.SubElement( # type: ignore[attr-defined]
Expand Down Expand Up @@ -274,8 +286,6 @@ class Author(_Person):
A feed/entry may have multiple authors.
"""

__name__ = "author"


class Contributor(_Person):
"""
Expand All @@ -284,7 +294,5 @@ class Contributor(_Person):
A feed/entry may have multiple contributor elements.
"""

__name__ = "contributor"


__all__ = ["Author", "Contributor", "Link", "NS"]
18 changes: 8 additions & 10 deletions fastkml/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class _XMLObject:

_default_ns: str = ""
_node_name: str = ""
__name__ = ""
name_spaces: Dict[str, str]

def __init__(
Expand All @@ -58,15 +57,9 @@ def etree_element(
verbosity: Verbosity = Verbosity.normal,
) -> Element:
"""Return the KML Object as an Element."""
if self.__name__:
element: Element = config.etree.Element( # type: ignore[attr-defined]
f"{self.ns}{self.__name__}",
)
else:
msg = "Call of abstract base class, subclasses implement this!"
raise NotImplementedError(
msg,
)
element: Element = config.etree.Element( # type: ignore[attr-defined]
f"{self.ns}{self.get_tag_name()}",
)
return element

def to_string(
Expand Down Expand Up @@ -102,6 +95,11 @@ def to_string(
),
)

@classmethod
def get_tag_name(cls) -> str:
"""Return the tag name."""
return cls.__name__

@classmethod
def _get_ns(cls, ns: Optional[str]) -> str:
return cls._default_ns if ns is None else ns
Expand Down
3 changes: 0 additions & 3 deletions fastkml/containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,6 @@ class Folder(_Container):
(Folders, Placemarks, #NetworkLinks, or #Overlays).
"""

__name__ = "Folder"


class Document(_Container):
"""
Expand All @@ -192,7 +190,6 @@ class Document(_Container):
extended data.
"""

__name__ = "Document"
_schemata: Optional[List[Schema]]

def __init__(
Expand Down
8 changes: 0 additions & 8 deletions fastkml/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ class Schema(_BaseObject):
"""

__name__ = "Schema"

def __init__(
self,
ns: Optional[str] = None,
Expand Down Expand Up @@ -202,8 +200,6 @@ def _get_kwargs(
class Data(_XMLObject):
"""Represents an untyped name/value pair with optional display name."""

__name__ = "Data"

def __init__(
self,
ns: Optional[str] = None,
Expand Down Expand Up @@ -290,8 +286,6 @@ class SchemaData(_XMLObject):
in the same KML file.
"""

__name__ = "SchemaData"

def __init__(
self,
ns: Optional[str] = None,
Expand Down Expand Up @@ -374,8 +368,6 @@ class ExtendedData(_XMLObject):
"""

__name__ = "ExtendedData"

def __init__(
self,
ns: Optional[str] = None,
Expand Down
3 changes: 0 additions & 3 deletions fastkml/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,6 @@ class Placemark(_Feature):
marks a point on the Earth in the 3D viewer.
"""

__name__ = "Placemark"
_geometry: Optional[KmlGeometry]

def __init__(
Expand Down Expand Up @@ -699,8 +698,6 @@ class NetworkLink(_Feature):
fly_to_view: Optional[bool]
_link: Optional[Link]

__name__ = "NetworkLink"

def __init__(
self,
ns: Optional[str] = None,
Expand Down
5 changes: 0 additions & 5 deletions fastkml/geometry.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ def etree_element(
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> Element:
self.__name__ = self.__class__.__name__
element = super().etree_element(precision=precision, verbosity=verbosity)
self._set_extrude(element)
self._set_altitude_mode(element)
Expand Down Expand Up @@ -365,7 +364,6 @@ def etree_element(
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> Element:
self.__name__ = self.__class__.__name__
element = super().etree_element(precision=precision, verbosity=verbosity)
assert isinstance(self.geometry, geo.Point)
coords = self.geometry.coords
Expand Down Expand Up @@ -423,7 +421,6 @@ def etree_element(
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> Element:
self.__name__ = self.__class__.__name__
element = super().etree_element(precision=precision, verbosity=verbosity)
assert isinstance(self.geometry, geo.LineString)
coords = self.geometry.coords
Expand Down Expand Up @@ -527,7 +524,6 @@ def etree_element(
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> Element:
self.__name__ = self.__class__.__name__
element = super().etree_element(precision=precision, verbosity=verbosity)
assert isinstance(self.geometry, geo.Polygon)
linear_ring = partial(LinearRing, ns=self.ns, extrude=None, tessellate=None)
Expand Down Expand Up @@ -677,7 +673,6 @@ def etree_element(
precision: Optional[int] = None,
verbosity: Verbosity = Verbosity.normal,
) -> Element:
self.__name__ = self.__class__.__name__
element = super().etree_element(precision=precision, verbosity=verbosity)
_map_to_kml = {mg: self.__class__ for mg in self.multi_geometries}
_map_to_kml.update(self.map_to_kml)
Expand Down
2 changes: 0 additions & 2 deletions fastkml/gx.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ def etree_element(
verbosity: Verbosity = Verbosity.normal,
name_spaces: Optional[Dict[str, str]] = None,
) -> Element:
self.__name__ = self.__class__.__name__
element = super().etree_element(precision=precision, verbosity=verbosity)
if self.track_items:
for track_item in self.track_items:
Expand Down Expand Up @@ -376,7 +375,6 @@ def etree_element(
verbosity: Verbosity = Verbosity.normal,
name_spaces: Optional[Dict[str, str]] = None,
) -> Element:
self.__name__ = self.__class__.__name__
element = super().etree_element(precision=precision, verbosity=verbosity)
if self.interpolate is not None:
i_element = cast(
Expand Down
4 changes: 0 additions & 4 deletions fastkml/links.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ class Link(_BaseObject):
A URL can be passed to the constructor, or the href can be set later.
"""

__name__ = "Link"

_href: Optional[str]
_refresh_mode: Optional[RefreshMode]
_refresh_interval: Optional[float]
Expand Down Expand Up @@ -324,5 +322,3 @@ class Icon(Link):
icon from an image that contains multiple icons
(often referred to as an icon palette).
"""

__name__ = "Icon"
5 changes: 0 additions & 5 deletions fastkml/overlays.py
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,6 @@ class PhotoOverlay(_Overlay):
https://developers.google.com/kml/documentation/kmlreference#photooverlay
"""

__name__ = "PhotoOverlay"

rotation: Optional[float]
# Adjusts how the photo is placed inside the field of view. This element is
# useful if your photo has been rotated and deviates slightly from a desired
Expand Down Expand Up @@ -677,7 +675,6 @@ class LatLonBox(_XMLObject):
Rotations are specified in a counterclockwise direction.
"""

__name__ = "LatLonBox"
north: Optional[float]
south: Optional[float]
east: Optional[float]
Expand Down Expand Up @@ -789,8 +786,6 @@ class GroundOverlay(_Overlay):
https://developers.google.com/kml/documentation/kmlreference#groundoverlay
"""

__name__ = "GroundOverlay"

altitude: Optional[float]
# Specifies the distance above the earth's surface, in meters, and is
# interpreted according to the altitude mode.
Expand Down
15 changes: 5 additions & 10 deletions fastkml/styles.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@ class StyleUrl(_BaseObject):
use a full URL along with # referencing.
"""

__name__ = "styleUrl"
url = None

def __init__(
Expand All @@ -86,6 +85,11 @@ def etree_element(
logger.warning("StyleUrl is missing required url.")
return element

@classmethod
def get_tag_name(cls) -> str:
"""Return the tag name."""
return "styleUrl"

@classmethod
def _get_kwargs(
cls,
Expand Down Expand Up @@ -259,7 +263,6 @@ def _get_kwargs(
class IconStyle(_ColorStyle):
"""Specifies how icons for point Placemarks are drawn."""

__name__ = "IconStyle"
scale = 1.0
# Resizes the icon. (float)
heading = None
Expand Down Expand Up @@ -375,7 +378,6 @@ class LineStyle(_ColorStyle):
(if extrusion is enabled).
"""

__name__ = "LineStyle"
width = 1.0
# Width of the line, in pixels.

Expand Down Expand Up @@ -441,7 +443,6 @@ class PolyStyle(_ColorStyle):
extrusions (which look like solid fences).
"""

__name__ = "PolyStyle"
fill = 1
# Boolean value. Specifies whether to fill the polygon.
outline = 1
Expand Down Expand Up @@ -517,7 +518,6 @@ def _get_kwargs(
class LabelStyle(_ColorStyle):
"""Specifies how the <name> of a Feature is drawn in the 3D viewer."""

__name__ = "LabelStyle"
scale = 1.0
# Resizes the label.

Expand Down Expand Up @@ -583,8 +583,6 @@ class BalloonStyle(_BaseObject):
The <bgColor>, if specified, is used as the background color of the balloon.
"""

__name__ = "BalloonStyle"

bg_color = None
# Background color of the balloon (optional). Color and opacity (alpha)
# values are expressed in hexadecimal notation. The range of values for
Expand Down Expand Up @@ -726,8 +724,6 @@ class Style(_StyleSelector):
so that they can be referenced by the individual Features that use them.
"""

__name__ = "Style"

def __init__(
self,
ns: Optional[str] = None,
Expand Down Expand Up @@ -809,7 +805,6 @@ class StyleMap(_StyleSelector):
the user mouses over the icon in Google Earth.
"""

__name__ = "StyleMap"
normal = None
highlight = None

Expand Down
4 changes: 0 additions & 4 deletions fastkml/times.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,6 @@ class _TimePrimitive(_BaseObject):
class TimeStamp(_TimePrimitive):
"""Represents a single moment in time."""

__name__ = "TimeStamp"

def __init__(
self,
ns: Optional[str] = None,
Expand Down Expand Up @@ -204,8 +202,6 @@ def _get_kwargs(
class TimeSpan(_TimePrimitive):
"""Represents an extent in time bounded by begin and end dateTimes."""

__name__ = "TimeSpan"

def __init__(
self,
ns: Optional[str] = None,
Expand Down

0 comments on commit 7af7903

Please sign in to comment.