315 questions
-2
votes
1
answer
60
views
Protocols and covariance - How to enable LSP in swift? [duplicate]
I want to keep some graph traversal algorithms as generic as possible and define a protocol for this purpose:
protocol Path {
var distance : Int { get}
var end : Node { get }
init (start:...
Best practices
0
votes
31
replies
200
views
Does dynamic_cast violate LSP?
Does the code below violates Liskov Substitution Principle (LSP)?
class Object
{
public:
virtual ~Object() = default;
};
class A : public Object
{
public:
void print()
{
std::...
-1
votes
1
answer
92
views
How to type-annotate write when subclassing io.RawIOBase, getting "Liskov substitution principle" violation
I want to type-annotate the write in a class that subclasses io.RawIOBase.
I'm struggling to get anything other than Any to type check, which is frustrating, because I should be able to use a much ...
0
votes
1
answer
106
views
Why does mypy not complain when overloading an abstract method's concrete implementation in the child class?
I am trying to wrap my head around the @overload operator, generics and the Liskov Substitution Principle. I usually make my abstract classes generic on some typevar T which is followed by concrete ...
-1
votes
1
answer
65
views
Converting a wider type to a more narrow type
I believe I am trying to convert a wider type to a more narrow type, which is the opposite to the Liskov substitution principle(?)
How can I tell the TS compiler that the narrowed properties "a&...
1
vote
2
answers
196
views
Usefulness of the substitution property of the Liskov Substitution Principle
The Liskov substitution principle states that a piece of code should remain correct if a superclass is replaced with its subclass (paraphrasing). What I don't understand; Why do we care about this ...
1
vote
2
answers
69
views
How does the Liskov Substitution Principle works with type specialization in concrete implementations of abstract classes?
Suppose we want to model different kinds of food; pizzas and pies. Both pizzas and pies do have a sort of topping, but their toppings are different.
We implement an abstract class Baked, and two ...
0
votes
1
answer
138
views
Interface method argument without a type - code smell?
I'm thinking about creating an interface method with an argument that can have a mixed type, to act like metadata. I don't know the metadata type upfront, but I know that some kind of it (or something ...
1
vote
2
answers
112
views
Why does the square-rectangle problem break Liskov substitution?
The Liskov Substitution Principle (LSP) imposes four behavioral requirements on subtypes (directly from Wikipedia):
Preconditions cannot be strengthened in the subtype
Postconditions cannot be ...
3
votes
1
answer
190
views
The Liskov Substitution Principle (LSP) in UML class diagrams
Is the isSubstitutable property meant to specify that a class and its generalisation comply with the Liskov Substitution Principle (LSP)? If not, is there an easy way to specify LSP compliance of a ...
0
votes
1
answer
129
views
Maintain explicit method signatures and LSP : dealing with extra arguments in Python
I'd like to share a OOP conception problem. My code is written in Python.
Here is a first non-valid code snippet that illustrates my problem.
Snippet 1
class Model(ABC):
@abstractmethod
def f(...
0
votes
0
answers
50
views
Enforce strict types while using generic with inheritance [duplicate]
I am trying to use in my project more strict type regulations. I want to use generics to enforce proper types. I've created an example (using AI) to make it clear and define my goals. I want to create ...
1
vote
0
answers
101
views
What should I break: Substitution capability or the Liskov Substitution Principle?
Suppose I have the following class:
template<typename T>
struct A { T* ptr; };
and a bunch of functions which take this class as a parameter, e.g.:
template <typename T>
int one_two_three(...
1
vote
2
answers
125
views
How to implement LSP (Liskov Substitution Principle) using Dart, in a real world example
The Liskov Substitution Principle (LSP) states that objects of a superclass should be able to be replaced with objects of a subclass without affecting the correctness of the program. In other words, a ...
2
votes
2
answers
72
views
LSP and virtual methods
I came across this example when I was trying to learn more about LSP, I am new to the OOPs world. You can find my question after the example. The example is as follows.
In mathematics, a Square is a ...
0
votes
1
answer
263
views
After upgrading neovim to 0.10, coc-flutter has started displaying parameters types in a weird way
After installing the latest neovin version (0.10), I can see extra pointers of variables names.
That's what I mean
enter image description here
So when I open a file all looks good and after loading ...
0
votes
2
answers
1k
views
Remove auto format and autofix from ZLS COMPLETELY (with nvim kickstart)
ZLS version is for 0.12.0 (I put in into PATH and lua script and checked if some plugin puts builtin LSP which I dont need).
In config_gen/config.json:
{
"name": "...
0
votes
1
answer
111
views
Is this breaking LSP - Post condition rule
Wanted to know if I am breaking Liskov Substitution Principle - post-condition rule here,
public class ProcessController
{
public virtual Dictionary<int, string> GetRunningProcess()
{
...
0
votes
0
answers
47
views
Covariant rule is important in LSP? And how does it impacts the client?
I have been going through LSP with C# and I have a few confusion.
Let just say
public class Employee
{
//properties
}
public class EmployeeExtendedDetail : Employee
{
//properties
}
...
0
votes
2
answers
75
views
What is not a covariant in OOPS
I have been trying understand the idea of covariant along with the Liskov substitution principle with some of the examples I found in the internet. This is one the those example I am currently ...
-1
votes
1
answer
147
views
How to select closed 2d polylines that don't have an specific block inside Autocad
I need a lisp routine to check the polygons (closed polylines) and verify if there's a block (selected by user) inside. After that, highlight the empty polygons, something like this picture.
Autocad
...
0
votes
1
answer
184
views
Can we provide an example and motivation on when to use covariant and contravariant?
I have some troubles finding real use cases of covariant/contravariant. I would like a concrete motivation and example on when covariant/contravariant is used, in particular, I would appreciate the ...
1
vote
0
answers
270
views
List is invariant because it violates LSP?
Python's type system says that list is invariant, and that List[int] is not a subtype of List[float].
Here's the Python code snippet:
def append_pi(lst: List[float]) -> None:
lst += [3.14]
...
2
votes
1
answer
90
views
How to type hint factories in subclasses
What is the correct way to type hint such subclassed factories, like those in the following popular pattern? The Liskov Substitution Principle originally only applies to instances, not classes, so I ...
1
vote
1
answer
2k
views
Module "lspconfig not found"
I'm using Neovim, Lua, and Lazy.nvim. I've installed nvim-lspconfig, as this screenshot proves:
Proof
Anyway, I wanted to use GDScript in Neovim, and this is what I ended up doing this:
-- General ...
1
vote
2
answers
7k
views
How do i install tsserver on Lazyvim?
I uncomment the lazy.lua to install tsserver and jsonls but both are failed to install. Can anybody solve this problem.
I installed everything that requires to run lazy vim. Then i uncomment the list ...
1
vote
1
answer
1k
views
Does the Prototype pattern violate the Liskov substitution principle?
I'm revisiting design patterns, especially those that I haven't used for a while/or at all.
And one of them is the Prototype pattern.
Different sources (e.g. this one) say that you should implement ...
0
votes
1
answer
162
views
disable task tag [TODO] jdtls [nvim, cmp, lua]
this is my lua config for cmp:
require('lspconfig')['jdtls'].setup {
root_dir = function(fname)
return vim.fn.getcwd()
end,
cmd = {
'jdtls',
'-vmargs',
'-...
0
votes
1
answer
486
views
Liskov substitution principle - example [closed]
Does Liskov substitution say that refference do the other class must be in a base class not in some derived class?
So inheritance and properties in case below is not right ?
abstract Location // place ...
0
votes
0
answers
114
views
How to enforce the Liskov substitution principle in Typescript
The compare (overridden) methods have different signatures than their super's compare:
abstract class Person {
public abstract compare(that: Person): boolean;
}
class Student extends Person {
...
5
votes
1
answer
1k
views
More elegant way to switch tqdm progress bars without LSP Pyright error
I'm creating a custom Python CLI module using docx2pdf.
The docx2pdf module is using tqdm to display progress bars while the .docx files are being converted to .pdf.
In my module I'm using the CLI log ...
3
votes
1
answer
645
views
How to config Unreal Engine5 C++ code auto completion for neovim?
I want to write Unreal Engine C++ code in Neovim, but don't how to config lsp server to enable the auto completion and formating for UE C++. Anyone who can help me out of this? Thx a lot.
I want to ...
1
vote
1
answer
3k
views
Enable ClangdSwitchSourceHeader to work with separate source and header files
I'm trying to set up my Neovim/LSP/Clangd setup at work. We use two different ways to store source (.cpp). and header (.h) files. The first way is the common approach, where both the source and header ...
3
votes
2
answers
6k
views
Unable to install java-language-server with mason lsp-zero
I am using lsp-zero which uses mason to install everything but whenever I try to install java-language-server I get the error.
Any help is appreciated.
Whenever i do :LspInstall and choose the first ...
0
votes
2
answers
100
views
Rascal LSP Typechecker
I am trying out figure out Rascal LSP and I have it working fine but I want to enable the TypeChecker but I can’t figure out how to construct a Builder object to pass to builder function from the code ...
1
vote
2
answers
115
views
How to pass the print function as argument to a forEach?
The print function can print integers and can be called like print(5). I want to do the same on an [Int] array.
However attempting to do the same on a forEach fails.
[1,2,3].forEach(print)
gives
...
1
vote
1
answer
882
views
Signature mismatch in derived class that is more explicit than the parent class
I have an abstract parent class like:
class Parent(ABC):
@classmethod
@abstractmethod
def method(cls, *args, basepath: str = None):
raise NotImplementedError()
and a concrete ...
2
votes
2
answers
272
views
C# compile error trying to apply Liskov Substitution Principle
I am reading a book about Design Patterns, and there's this chapter on the Liskov Substitution Principle that says to do this (and other tasks) to achieve the principle:
Parameter types in a method ...
-1
votes
1
answer
241
views
Object-oriented paradigms (SOLID) violated in Python? (example: subclassing of tuple to implement FractionTuple)
I was quite surprised to see that Python - at least partially - seems to violate some oo / SOLID principles.
Example:
class FractionTuple(tuple):
def __new__(cls, p, q):
# Ensure that p and q are ...
3
votes
0
answers
937
views
Overloaded signature supposedly incompatible with supertype, despite not strengthening preconditions
Imagine being given the following base class that you have no control over:
from typing import Optional
class A:
def foo(self, x: Optional[bool] = None) -> None:
pass
Now you want to ...
8
votes
0
answers
3k
views
How to get pyright to use the current conda environment automatically?
I would like pyright installed by Mason to use the current conds environment, that is the one used when opening neovim.
If I put a pyrightconfig.json shown below in root dir of my project, this will ...
0
votes
0
answers
111
views
Unity C# - Liskov Substitution Principle
I was rewriting some code to practice SOLID and I think my code is failing the Liskov Substitution Principle. I don't know if this code is correct, can someone help me?
That code was created to ...
0
votes
0
answers
42
views
Proper way to satisfy liskov substitution principle?
How should I properly satisfy the Liskov Substitution Principle in this sample?
class User(ABC): # App core logic
def add_photo(self, photo: bytes, ) -> None:
...
class FacebookUser(...
7
votes
2
answers
6k
views
mypy seems to think that (*args, **kwargs) could match to any funtion signature?
How does mypy apply the Liskov substitution principle to *args, **kwargs parameters?
I thought the following code should fail a mypy check since some calls to f allowed by the Base class are not ...
0
votes
1
answer
981
views
Incorrect diagnostics in Nvim LSP (Python)
I have installed lsp server for python and have def like this one:
def get_info_about_file(db: Session, name_of_file: str) -> schema.File:
return db.query(models.File).filter(models.File.name ==...
0
votes
1
answer
1k
views
How do i connect LSP to Webview2 monaco editor
I have https://github.com/arnoson/monaco-lua-example right here, which is an example of connecting a language server to the monaco editor (mine is especially hosted by webview2.)
https://github.com/...
0
votes
3
answers
300
views
Does liskov's substitution mean that all functions that call a method to an obj has to have the exact same behavior in what properties it alters?
I'm trying to figure out the Liskov's Substitution Principle and the example of the rectangle and square doesn't really click with me. So the example for the rectangle and square goes that if you have ...
0
votes
1
answer
6k
views
neovim lsp-zero configure file throwing error from lsp.setup() function
I am trying to install the "lsp-zero" package and I am receiving the error posted below. I am desperate after trying to figure out what is going on. Any help would be great thank you.
I am ...
2
votes
2
answers
197
views
Liskov Substitution Principle Violation Rules
The purpose of inheritance is to inherit and extend.
So my question is that if child class have more method that will it break the LSP ?
So in my example I have 2 classes Rectangle and Square. Square ...
0
votes
3
answers
1k
views
How to handle a List of Base class that contains elements of Derived classes
public async IEnumerable<ParentClass> ReadResultAsync
{
var results = new List<ParentClass>();
results.Add(ChildClassA);
results.Add(ChildClassB);
return results;
}
I do ...