Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Removes dependency on the overrides package (#5490)
Browse files Browse the repository at this point in the history
* Removes dependency on the overrides package

* Changelog

* Various fixes for mypy

* Update cached_path dependency

* What happened here?

* Formatting

* Fix more tests

* One more missing overrides
  • Loading branch information
dirkgr authored Dec 1, 2021
1 parent b99376f commit 1caf0da
Show file tree
Hide file tree
Showing 144 changed files with 145 additions and 547 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Fixed the docstring information for the `FBetaMultiLabelMeasure` metric.
- Various fixes for Python 3.9

### Removed

- Removed dependency on the overrides package


## [v2.8.0](https://github.com/allenai/allennlp/releases/tag/v2.8.0) - 2021-11-01

### Added
Expand Down
3 changes: 0 additions & 3 deletions allennlp/commands/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import sys
from typing import Any, Optional, Tuple, Set

from overrides import overrides

from allennlp import __version__
from allennlp.commands.build_vocab import BuildVocab
from allennlp.commands.cached_path import CachedPath
Expand Down Expand Up @@ -42,7 +40,6 @@ def _is_empty_default(default: Any) -> bool:
return not bool(default)
return False

@overrides
def add_argument(self, *args, **kwargs):
# Add default value to the help message when the default is meaningful.
default = kwargs.get("default")
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/build_vocab.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import tarfile
import tempfile

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common.file_utils import CacheFile
Expand All @@ -22,7 +21,6 @@

@Subcommand.register("build-vocab")
class BuildVocab(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Build a vocabulary from an experiment config file."""
subparser = parser.add_parser(self.name, description=description, help=description)
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/cached_path.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import argparse
import logging

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common.file_utils import (
Expand All @@ -23,7 +22,6 @@
class CachedPath(Subcommand):
requires_plugins: bool = False

@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Cache remote files to the AllenNLP cache."""
subparser = parser.add_parser(
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/checklist.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import sys
import json

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common.checks import check_for_gpu, ConfigurationError
Expand All @@ -20,7 +19,6 @@

@Subcommand.register("checklist")
class CheckList(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:

description = """Run the specified model through a checklist suite."""
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/count_instances.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import argparse
import logging

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common.params import Params
Expand All @@ -16,7 +15,6 @@

@Subcommand.register("count-instances")
class CountInstances(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Count the number of training instances in an experiment config file."""
subparser = parser.add_parser(self.name, description=description, help=description)
Expand Down
3 changes: 1 addition & 2 deletions allennlp/commands/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import logging
from typing import Union, Dict, List, Tuple, NamedTuple, cast

from overrides import overrides

import termcolor
import torch

Expand All @@ -29,7 +29,6 @@
class Diff(Subcommand):
requires_plugins: bool = False

@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Display a diff between two model checkpoints."""
long_description = (
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

from copy import deepcopy

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common import logging as common_logging
Expand All @@ -25,7 +24,6 @@

@Subcommand.register("evaluate")
class Evaluate(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Evaluate the specified model + dataset(s)"""
subparser = parser.add_parser(
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/find_learning_rate.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
from typing import List, Tuple
import itertools

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common import Params, Tqdm
Expand All @@ -29,7 +28,6 @@

@Subcommand.register("find-lr")
class FindLearningRate(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:

description = """Find a learning rate range where loss decreases quickly
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/predict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import sys
import json

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common import logging as common_logging
Expand All @@ -23,7 +22,6 @@

@Subcommand.register("predict")
class Predict(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:

description = """Run the specified model against a JSON-lines input file."""
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/print_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import logging
import os

from overrides import overrides

from allennlp.commands.subcommand import Subcommand

Expand All @@ -19,7 +18,6 @@
class PrintResults(Subcommand):
requires_plugins: bool = False

@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:

description = """Print results from allennlp training runs in a helpful CSV format."""
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/push_to_hf.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import argparse
import logging

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common.push_to_hf import push_to_hf
Expand All @@ -16,7 +15,6 @@

@Subcommand.register("push-to-hf")
class PushToHf(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Push a model to the Hugging Face Hub.
Expand Down
4 changes: 1 addition & 3 deletions allennlp/commands/subcommand.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import argparse
from typing import Callable, Dict, Optional, Type, TypeVar

from overrides import overrides

from allennlp.common import Registrable

Expand Down Expand Up @@ -37,8 +36,7 @@ def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.Argument
raise NotImplementedError

@classmethod
@overrides
def register(
def register( # type: ignore
cls: Type[T], name: str, constructor: Optional[str] = None, exist_ok: bool = False
) -> Callable[[Type[T]], Type[T]]:
super_register_fn = super().register(name, constructor=constructor, exist_ok=exist_ok)
Expand Down
2 changes: 0 additions & 2 deletions allennlp/commands/tango.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from typing import Union, Dict, Any, List, Optional
import warnings

from overrides import overrides

from allennlp.commands.subcommand import Subcommand
from allennlp.common.params import Params
Expand All @@ -24,7 +23,6 @@

@Subcommand.register("tango")
class Tango(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Run a tango experiment file."""
subparser = parser.add_parser(self.name, description=description, help=description)
Expand Down
3 changes: 1 addition & 2 deletions allennlp/commands/test_install.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import logging
import pathlib

from overrides import overrides

import torch

import allennlp
Expand All @@ -21,7 +21,6 @@

@Subcommand.register("test-install")
class TestInstall(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Test that AllenNLP is installed correctly."""
subparser = parser.add_parser(
Expand Down
3 changes: 1 addition & 2 deletions allennlp/commands/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import torch
import torch.distributed as dist
import torch.multiprocessing as mp
from overrides import overrides


from allennlp.commands.subcommand import Subcommand
from allennlp.common import Params, Registrable, Lazy
Expand All @@ -36,7 +36,6 @@

@Subcommand.register("train")
class Train(Subcommand):
@overrides
def add_subparser(self, parser: argparse._SubParsersAction) -> argparse.ArgumentParser:
description = """Train the specified model on the specified dataset."""
subparser = parser.add_parser(self.name, description=description, help="Train a model.")
Expand Down
3 changes: 0 additions & 3 deletions allennlp/common/params.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from os import PathLike
from typing import Any, Dict, List, Union, Optional, TypeVar, Iterable, Set

from overrides import overrides

# _jsonnet doesn't work on Windows, so we have to use fakes.
try:
Expand Down Expand Up @@ -197,7 +196,6 @@ def __init__(self, params: Dict[str, Any], history: str = "") -> None:
self.params = _replace_none(params)
self.history = history

@overrides
def pop(self, key: str, default: Any = DEFAULT, keep_as_dict: bool = False) -> Any:

"""
Expand Down Expand Up @@ -261,7 +259,6 @@ def pop_bool(self, key: str, default: Any = DEFAULT) -> Optional[bool]:
else:
raise ValueError("Cannot convert variable to bool: " + value)

@overrides
def get(self, key: str, default: Any = DEFAULT):
"""
Performs the functionality associated with dict.get(key) but also checks for returned
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional, Iterable, Tuple, Union
import itertools
import numpy as np
from overrides import overrides

from checklist.editor import MunchWithAdd as CheckListTemplate
from checklist.test_suite import TestSuite
from checklist.test_types import MFT
Expand Down Expand Up @@ -53,7 +53,6 @@ def preds_and_confs_fn(data):

return preds_and_confs_fn

@overrides
def _format_failing_examples(
self,
inputs: Tuple,
Expand Down Expand Up @@ -95,7 +94,6 @@ def context_punctuation(x):

return context_punctuation

@overrides
def _setup_editor(self):
super()._setup_editor()

Expand Down Expand Up @@ -142,7 +140,6 @@ def _setup_editor(self):

self.editor.add_lexicon("comp_pairs", comp_pairs, overwrite=True)

@overrides
def _default_tests(self, data: Optional[Iterable[Tuple]], num_test_cases: int = 100):
super()._default_tests(data, num_test_cases)
self._setup_editor()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Optional, Iterable, List, Union, Tuple
import numpy as np
from overrides import overrides

from checklist.test_suite import TestSuite
from checklist.test_types import MFT, INV, DIR, Expect
from checklist.perturb import Perturb
Expand Down Expand Up @@ -47,7 +47,6 @@ def __init__(
self._negative = negative
super().__init__(suite, **kwargs)

@overrides
def _prediction_and_confidence_scores(self, predictor: Predictor):
def preds_and_confs_fn(data):
labels = []
Expand All @@ -65,7 +64,6 @@ def preds_and_confs_fn(data):

return preds_and_confs_fn

@overrides
def _format_failing_examples(
self,
inputs: Tuple,
Expand All @@ -86,7 +84,6 @@ def _format_failing_examples(

return ret

@overrides
def _default_tests(self, data: Optional[Iterable[str]], num_test_cases: int = 100):
super()._default_tests(data, num_test_cases)
self._setup_editor()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from typing import Optional, Tuple, Iterable, Callable, Union
import itertools
import numpy as np
from overrides import overrides

from checklist.test_suite import TestSuite
from checklist.test_types import MFT, INV, DIR, Expect
from checklist.perturb import Perturb
Expand Down Expand Up @@ -78,7 +78,6 @@ def preds_and_confs_fn(data):

return preds_and_confs_fn

@overrides
def _format_failing_examples(
self,
inputs: Tuple,
Expand Down Expand Up @@ -119,7 +118,6 @@ def typos(cls):
def punctuation(cls):
return _wrap_apply_to_each(utils.toggle_punctuation, both=False)

@overrides
def _setup_editor(self):
super()._setup_editor()

Expand Down Expand Up @@ -358,7 +356,6 @@ def _setup_editor(self):
subclasses = [(a, b[i]) for a, b in subclasses for i in range(len(b))]
self.editor.add_lexicon("subclasses", subclasses, overwrite=True)

@overrides
def _default_tests(self, data: Optional[Iterable[Tuple]], num_test_cases: int = 100):
super()._default_tests(data, num_test_cases)
self._setup_editor()
Expand Down
Loading

0 comments on commit 1caf0da

Please sign in to comment.