Skip to content

Commit 8142640

Browse files
committed
Change _DatabaseEntity._ENTITY_TYPE to enum
1 parent 33d5bdb commit 8142640

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

wn/_core.py

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11

2+
import enum
3+
import textwrap
4+
import warnings
25
from collections.abc import Callable, Iterator, Sequence
36
from typing import Optional, TypeVar
4-
import warnings
5-
import textwrap
67

78
import wn
89
from wn._types import (
@@ -46,10 +47,22 @@
4647
_INFERRED_SYNSET = '*INFERRED*'
4748

4849

50+
class _EntityType(str, enum.Enum):
51+
"""Identifies the database table of an entity."""
52+
LEXICONS = 'lexicons'
53+
ENTRIES = 'entries'
54+
SENSES = 'senses'
55+
SYNSETS = 'synsets'
56+
SENSE_RELATIONS = 'sense_relations'
57+
SENSE_SYNSET_RELATIONS = 'sense_synset_relations'
58+
SYNSET_RELATIONS = 'synset_relations'
59+
UNSET = ''
60+
61+
4962
class _DatabaseEntity:
5063
__slots__ = '_id',
5164

52-
_ENTITY_TYPE = ''
65+
_ENTITY_TYPE: _EntityType = _EntityType.UNSET
5366

5467
def __init__(self, _id: int = NON_ROWID):
5568
self._id = _id # Database-internal id (e.g., rowid)
@@ -122,7 +135,7 @@ class Lexicon(_DatabaseEntity):
122135
'version', 'url', 'citation', 'logo')
123136
__module__ = 'wn'
124137

125-
_ENTITY_TYPE = 'lexicons'
138+
_ENTITY_TYPE = _EntityType.LEXICONS
126139

127140
def __init__(
128141
self,
@@ -341,7 +354,7 @@ class Word(_LexiconElement):
341354
__slots__ = 'id', 'pos', '_forms'
342355
__module__ = 'wn'
343356

344-
_ENTITY_TYPE = 'entries'
357+
_ENTITY_TYPE = _EntityType.ENTRIES
345358

346359
def __init__(
347360
self,
@@ -513,7 +526,7 @@ class Synset(_Relatable):
513526
__slots__ = 'pos', '_ili'
514527
__module__ = 'wn'
515528

516-
_ENTITY_TYPE = 'synsets'
529+
_ENTITY_TYPE = _EntityType.SYNSETS
517530

518531
def __init__(
519532
self,
@@ -869,7 +882,7 @@ class Sense(_Relatable):
869882
__slots__ = '_entry_id', '_synset_id'
870883
__module__ = 'wn'
871884

872-
_ENTITY_TYPE = 'senses'
885+
_ENTITY_TYPE = _EntityType.SENSES
873886

874887
def __init__(
875888
self,

0 commit comments

Comments
 (0)